<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>组件中的数据和方法</title>
</head>
<body>
<div id="app">
    <cpn></cpn>
</div>

<template id="cpn">
    <h1>清晨的问候</h1>
    <h1>{{ grate }}</h1>
    <button v-on:click="btnClicked">更新</button>
</template>
<script type="module">
    import {createApp, ref} from "../../../../js/vue.esm-browser.js";
    import {defineComponent} from "../../../../js/vue.esm-browser.js";

    let cpn = defineComponent(
        {
            template: "#cpn",
            setup() {
                let grate = ref("Hello, World!")
                function btnClicked() {
                    grate.value = "Hi, I'am here!"
                }
                return {
                    grate,
                    btnClicked,
                };
            }
        }
    );

    let app = createApp({
        setup() {
            return {}
        },
        components: {
            cpn,
        }
    })

    app.mount("#app")
</script>
</body>
</html>